<template>
    <el-table :data="list_data" style="width: 100%" :table-layout="'auto'">
        <el-table-column prop="uid" label="Uid"/>
        <el-table-column prop="email" label="Email"/>
        <el-table-column prop="name" label="Name"/>
        <el-table-column prop="password" label="Password"/>
    </el-table>
</template>

<script>
    import {ElLoading, ElMessage} from "element-plus";
    import Qs from 'qs'
    import axios from "axios";

    export default {
        name: "UserList",
        data() {
            return {
                list_data: [],
            }
        },
        mounted() {
            let _this = this;
            window.onload = function () {
                const loading = ElLoading.service({
                    lock: true,
                    text: 'Loading',
                    background: 'rgba(0, 0, 0, 0.7)',
                })
                let this_ = _this;
                axios.post('/admin/api/list', Qs.stringify({
                    "index": 1,
                    "end": 100
                }))
                    .then(function (response) {
                        let user_data = response.data

                        if (user_data === '0'){
                            ElMessage({message: "权限不足", type: 'error'})
                            return
                        }
                        else if (user_data === '-1'){
                            ElMessage({message: "非法参数", type: 'error'})
                            return
                        }
                        else if (user_data === '-2'){
                            ElMessage({message: "范围过大", type: 'error'})
                            return
                        }

                        this_.list_data = user_data

                        setTimeout(() => {
                            loading.close()
                        }, 500)
                    })
                    .catch(function (error) {
                        console.log(error);
                        ElMessage({message: "服务器异常，获取用户信息失败", type: 'error'})
                        setTimeout(() => {
                            loading.close()
                        }, 500)
                    });
                setTimeout(() => {
                    loading.close()
                }, 5000)
            }
        },
    }
</script>

<style scoped>

</style>